unit Edparts;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, DBTables, DB, StdCtrls, ExtCtrls, Mask, DBCtrls, DBLookup, patterns,
  Buttons;

type
  TEdPartsForm = class(TForm)
    Panel1: TPanel;
    Navigator: TDBNavigator;
    Panel2: TPanel;
    Label1: TLabel;
    DBEdit2: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit7: TDBEdit;
    DBEdit8: TDBEdit;
    DBEdPartNo: TDBEdit;
    Label6: TLabel;
    DBEdit3: TDBEdit;
    PrintBtn: TSpeedButton;
    DataComboBox1: TDBLookupComboBox;
    OKButton: TButton;
    CancelButton: TButton;
    Bevel1: TBevel;
    PartsSource1: TDataSource;
    procedure PrintBtnClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  public
    procedure Edit(PartNo: Double);
    class function getInstance: TEdPartsForm;
  end;

  TControllerEdParts = class(TController)
  private
  protected
    procedure DoCommand(Command: string; const args: string=''); override;
  public
  end;

var
  EdPartsForm: TEdPartsForm;

implementation

{$R *.DFM}

uses DataMod, commandlist;

class function TEdPartsForm.getInstance: TEdPartsForm;
begin
  if not assigned(EdPartsForm) then
    EdPartsForm := TEdPartsForm.Create(Application);
  result := EdPartsForm;
end;


procedure TEdPartsForm.Edit(PartNo: Double);
begin
  TMastData.getInstance.Parts.Open;
  TMastData.getInstance.Parts.Locate('PartNo', PartNo, []);
  ShowModal;
end;

procedure TEdPartsForm.PrintBtnClick(Sender: TObject);
begin
  if MessageDlg('   Print this form?', mtConfirmation, [mbYes, mbNo], 0)
    = mrYes then Print;
end;

procedure TEdPartsForm.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  CanClose := TMastData.getInstance.DataSetApplyUpdates(TMastData.getInstance.Parts, ModalResult = mrOK);
end;


procedure TControllerEdParts.DoCommand(Command: string; const args: string='');
begin
  if Command = CMD_EDIT_PARTS then
  begin
    if args = 'on' then
    begin
      TEdPartsForm.getInstance.Edit(TMastData.getInstance.PartsQueryPartNo.Value);
      TMastData.getInstance.PartsQuery.Close;
      TMastData.getInstance.PartsQuery.Open;
    end else begin
      TEdPartsForm.getInstance.Edit(TMastData.getInstance.PartsPartNo.Value);
    end;
  end;
end;

initialization
  ControlCenter.RegController(TControllerEdParts.Create);

end.

